package it.polimi.swKnights.SWIMv2.ejb.entityBeans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.TableGenerator;

/**
 * Entity implementation class for Entity: PrivateMessage
 * 
 */
@Entity
@TableGenerator(name = "Message_Sequence")
public class PrivateMessage implements Serializable
{
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "Message_Sequence")
	private int id;

	private String object;

	private String text;

	@Column(nullable = false)
	private String sent_by;

	@Column(nullable = false)
	private Date date;

	@ManyToOne
	private RegisteredUser sender;

	@OneToMany(mappedBy = "message")
	private List<ReceivedMessages> messageReferences;

	/*
	 * Serial Version ID
	 */

	private static final long serialVersionUID = 1L;

	/*
	 * Constructors
	 */

	public PrivateMessage()
	{
		super();
	}

	public PrivateMessage(String sent_by)
	{
		this.sent_by = sent_by;
		this.date = new Date();
	}

	/*
	 * Getters and setters
	 */

	public String getObject()
	{
		return object;
	}

	public void setObject(String object)
	{
		this.object = object;
	}

	public String getText()
	{
		return text;
	}

	public void setText(String text)
	{
		this.text = text;
	}

	public String getSent_By()
	{
		return sent_by;
	}

	public List<String> getRecipients()
	{
		List<String> recipientList = new ArrayList<String>();
		for (ReceivedMessages reference : this.messageReferences)
		{
			recipientList.add(reference.getRecipient());
		}
		return recipientList;
	}

	public Date getDate()
	{
		return date;
	}

	public RegisteredUser getSender()
	{
		return this.sender;
	}

	public void setSender(RegisteredUser sender)
	{
		this.sender = sender;
	}

	public int getId()
	{
		return this.id;
	}

}